package sh.grapendaal.tsuushin.module.uno.engine.domain.achievement.impl;

import sh.grapendaal.tsuushin.module.uno.engine.UnoRules;
import sh.grapendaal.tsuushin.module.uno.engine.domain.achievement.Achievement;
import sh.grapendaal.tsuushin.module.uno.engine.dto.GameState;
import sh.grapendaal.tsuushin.module.uno.engine.dto.PlayerState;

public class LastDitchEffortAchievement extends Achievement {

	@Override
	public String getName() {
		return "Last Ditch Effort";
	}

	@Override
	public String getDescription() {
		return "Change the suit when another player has Uno.";
	}

	@Override
	public boolean isEarned(GameState gameState) {
		boolean playerWithUno = false;
		for (PlayerState player : gameState.getPlayers()) {
			playerWithUno |= UnoRules.hasUno(player.getCards());
		}
		
		return playerWithUno && gameState.getPlayed().getSuit() != gameState.getTopCard().getSuit();
	}

}
